<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Retrieving GO ID's using AJAX</title>
		<meta name="generator" content="Studio 3 http://aptana.com/">
		<meta name="author" content="Gavin Koh">
		<!-- Date: 2011-08-13 -->
		<script type="text/javascript"><!--
			function getResult() {
				var query = prompt("Enter a UniProt ID:", "P37173")
				var ajax;
				if (window.XMLHttpRequest) {
					ajax = new XMLHttpRequest();
				} else {
					ajax = new ActiveXObject("Microsoft.XMLHTTP");
				};
				var queryXML = 'query=<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE Query><Query virtualSchemaName="default" formatter="CSV" header="0" uniqueRows="0" count ="" datasetConfigVersion="0.6"><Dataset name="uniprot" interface="default"><Filter name="accession" value="' +
					query +
					'"/><Attribute name="go_id" /><Attribute name="accession" /></Dataset></Query>';
				ajax.onreadystatechange=function() {
					if (ajax.readyState==4 && ajax.status==200) {
						document.getElementById("uniprotID").innerHTML=query;
						document.getElementById("result").innerHTML=ajax.responseText;
						responseSlices = ajax.responseText.split("\n");
						document.getElementById("firstSlice").innerHTML = responseSlices[0];
						responseSlicedSlices = [];
						for (i=0; i < responseSlices.length; i++) {
							responseSlicedSlices.push(responseSlices[i].split(",",1));
						};
						document.getElementById("secondSlice").innerHTML = responseSlicedSlices.toString();
						document.getElementById("lengthSecondSlice").innerHTML = responseSlicedSlices.length;
					};
				};
				ajax.open("POST", "http://www.ebi.ac.uk/uniprot/biomart/martservice", true);
				ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				ajax.setRequestHeader("Content-length", queryXML.length);
				ajax.setRequestHeader("Connection", "close");
				ajax.send(queryXML);
			};
		-->
		</script>
	</head>
	<body>
		<input type="button" onclick="getResult()" value="Get Result!" />
		<p>First slice: <span id="firstSlice"></span></p>
		<p>Second slice: <span id="secondSlice"></span></p>
		<p>Length: <span id="lengthSecondSlice"></span></p>
		<p>Uniprot ID: <span id="uniprotID"></span></p></p>
		<p>Result: <span id="result"></span></p>
	</body>
</html>
